package org.Vancl.Dao.ImpI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.Vancl.Dao.menuDao;
import org.Vancl.entity.menu;
import org.Vancl.utils.BaseDao;

public class menuDaoImpI extends BaseDao implements menuDao {

	
	public List<menu> getid(int id) {
		String sql="SELECT * FROM Navigation n INNER JOIN menu m ON n.`n_id`=m.`m_nid` where m.`m_nid`=?";
		ResultSet rs=super.executeQuery(sql, id);
		List<menu> menulist=new ArrayList();
		try {
			while(rs.next()) {
				menu menu=new menu();
				menu.setM_id(rs.getInt("m_id"));
				menu.setM_name(rs.getString("m_name"));
				menu.setM_nid(rs.getInt("m_nid"));
				menulist.add(menu);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return menulist;
	}

	@Override
	public int add(menu menu) {
		String sql="INSERT INTO menu(m_name,m_nid) VALUES (?,?)";
		return super.executeUpdate(sql, menu.getM_name(),menu.getM_nid());
	}

	@Override
	public int update(menu menu) {
		String sql="update menu set m_name=? where m_id=?";
		return super.executeUpdate(sql, menu.getM_name(),menu.getM_id());
	}

	@Override
	public menu getid1(int id) {
		String sql="select * from menu where m_id=?";
		ResultSet rs=super.executeQuery(sql, id);
		menu menu=null;
		try {
			while (rs.next()) {
				menu=new menu();
				menu.setM_id(rs.getInt("m_id"));
				menu.setM_name(rs.getString("m_name"));
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return menu;
	}

}
